import { pAjax } from "./gather";

const search = document.querySelector('.search_input');
const search_btn = document.querySelector('.search_btn');


const ul = document.querySelector('.search_right_ul');

const body = document.body;
let yong = {
    current: 1,
    pagesize: 12,
    search: '',
    filter: '',
    saleType: 10,
    sortType: 'id',
    sortMethod: 'ASC',
    category: ''
}
//商品

async function showPlay() {

    let res = await pAjax({
        url: 'http://localhost:8888/goods/list',
        data: yong,
        dataType: 'json',
    })
    fun(res)
}


//点击
play();
function play() {
    //搜索
    search.addEventListener('input', () => {
        yong.search = search.value.trim();
        yong.current = 1;
        showPlay()
        console.log(yong.search)
    });

}


// 点击后面的搜索
playAuto();
function playAuto() {

    search_btn.addEventListener('click', () => {
        console.log(123)
    })
    body.addEventListener('click', e=>{
        console.log(123123);
        let target = e.target;
        if (target.className !== 'search_input') {
            // 首先要判断 开关的一个状态
            ul.style.display ="none";

        }else{
            ul.style.display ="flex";

        }
    })


}

function fun(res){

    let str = ''
    res.list.forEach(item => {
        str += `
        <li>${item.title}</li>
        `
    })
    console.log(str)

    ul.innerHTML = str
    // 让我们的ul盒子显示出来
    ul.style.display = 'flex'
}



